package moodish.client.gui.utils;

import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.table.AbstractTableModel;

import moodish.client.user.User;

public class FriendTableModel extends AbstractTableModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private ArrayList<User> friendList = new ArrayList<User>();



	@Override
	public String getColumnName(int column) {
		switch (column) {
		case 0:
			return "NickName";
		default:
			return null;
		}
	}

	@Override
	public int getColumnCount() {
		return 1;
	}

	@Override
	public int getRowCount() {
		return friendList.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return friendList.get(rowIndex).getNickName();
	}

	public void addFriendToTable(User user){
		friendList.add(user);
		fireTableDataChanged();
	}

	public void removeFriend(String nickName){
		Iterator<User> it = friendList.iterator();
		System.out.println("ESTOU TODO DENTRO");
		while(it.hasNext()){
			if(it.next().getNickName().equals(nickName)){
				it.remove();
				fireTableDataChanged();
			}
		}
	}

	public User getUser(int selected){
		if(selected > -1){
			return friendList.get(selected);
		}
		return null;
	}

	public ArrayList<User> getFriendList() {
		return friendList;
	}
}
